package com.uenpay.oem.ui.reserver;

import com.uenpay.oem.data.bean.UserIdCardInfo;
import com.uenpay.oem.data.model.IUserAuthModel;
import com.uenpay.oem.data.modelImpl.BankCardModel;
import com.uenpay.oem.data.modelImpl.UserAuthModel;
import com.uenpay.service.bean.BankCardInfo;
import com.uenpay.service.model.IBankCardModel;
import com.uenpay.util.common.PicUtil;
import com.uenpay.util.net.listener.HttpOnNextListener;

/**
 * Author: liulou
 * Date: 2017/6/18.
 * desc:
 */

public class CardCameraPresenter implements CardCameraContract.Presenter {

    private CardCameraContract.View mView;
    private IBankCardModel cardModel;

    public CardCameraPresenter(CardCameraContract.View view) {
        this.mView = view;
        cardModel = new BankCardModel();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void recognition(byte[] data) {
        cardModel.recognitionUserBank(PicUtil.byteToBase64(data),recognitionListener);
    }

    private HttpOnNextListener<BankCardInfo> recognitionListener = new HttpOnNextListener<BankCardInfo>() {
        @Override
        public void onStart() {
            mView.showLoading();
        }

        @Override
        public void onNext(BankCardInfo info) {
            mView.dismissLoading();
            mView.setData(info);

        }

        @Override
        public void onComplete() {
            mView.dismissLoading();
        }

        @Override
        public void onError(Throwable e) {
            mView.dismissLoading();
        }
    };
}
